import React from 'react'
import { connect } from 'dva'
import { Input } from 'antd'

/**
 * [Keywords 时间段单选组合]
 */
class Keywords extends React.Component {
  state = {
    value: this.props.value,
  }

  componentWillReceiveProps(nextProps) {
    if(nextProps.value!==this.props.value){
      this.setState({
        value:nextProps.value,
      })
    }
  }

  handleChange = (e) => {
   
    this.setState({
      value:e.target.value,
    })
    
  }
  handleSearch = (value) => {
    console.log(121,value);
    
    this.changeRouter(value)
    
  }

  changeRouter(val) {
      console.log(1212,val);
      
    //  保存查询参数到URL
    const payload = this.props.location
    payload.query.keywords=val
    this.props.dispatch({
      type: `app/changeRouter`,
      payload
    })
  }
  render() {
    const { value, data } = this.state
    console.log(67701,this.props);
    
    
    return (
        <Input.Search
        // placeholder="input search text"
        defaultValue={this.props.value}
        value={this.state.value}
        onSearch={this.handleSearch.bind(this)}
        onChange={this.handleChange.bind(this)}
        style={{ width: 200 }}
      />
    )
  }
}
Keywords.defaultProps = {
  value: '',
  location: {
    pathname: '/',
    query: {},
  },
}

export default connect()(Keywords)
